Skip to content

Fix wasm SQLite streaming statement lifetime#37

Merged
subframe7536 merged 1 commit into
masterfrom
codex/review-packages-for
Jul 3, 2026
Merged

Fix wasm SQLite streaming statement lifetime#37
subframe7536 merged 1 commit into
masterfrom
codex/review-packages-for

Conversation

@subframe7536

Copy link
Copy Markdown
Owner

Motivation

  • Prevent prepared statements from being freed/finalized while their stream iterators are still reading, which caused dropped rows or iterator lifetime issues for wasm-backed dialects.
  • Enable the shared streaming test for sql.js so sql.js gets the same streaming coverage as other wasm dialects.

Description

  • Replace inline iterator use with iterateWithStatement helper that prepares the statement, binds parameters, yields rows via a dedicated iterator generator, and only frees/finalizes the statement after iteration completes in sqljs and official-wasm dialects.
  • Stop calling the transient runWithStatement for streaming paths and instead return an iterator that keeps the statement alive for the full stream lifetime.
  • Remove the now-unused runWithStatement declaration from sqljs.ts to satisfy type checks.
  • Enable the streaming test for SqlJsDialect by removing the supportStream=false override in the wasm tests.

Testing

  • Ran pnpm test, which executed the test suite and reported Test Files 5 passed (5) and Tests 10 passed (10).
  • Ran type checking and linting with pnpm typecheck && pnpm lint, which completed successfully (no TypeScript or lint errors).

Codex Task

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a lifetime bug in WASM-backed SQLite streaming by ensuring prepared statements remain alive for the entire duration of streamed iteration, preventing dropped rows and iterator lifetime failures. It also enables streaming coverage for the SqlJsDialect in the WASM dialect test suite.

Changes:

  • Replace the prior “prepare + return iterator” pattern with iterateWithStatement(...) so statement cleanup happens only after iteration completes (or is closed) in sqljs and official-wasm.
  • Stop using the transient runWithStatement for streaming paths (while keeping it for non-streaming query execution where appropriate).
  • Enable the shared streaming test for sql.js by removing the supportStream=false override.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/dialect-wasm/test/index.test.ts Enables streaming coverage for SqlJsDialect by using the default streaming-enabled testCase behavior.
packages/dialect-wasm/src/dialects/sqljs.ts Introduces iterateWithStatement generator to keep sql.js statements alive until iteration completes, then frees them.
packages/dialect-wasm/src/dialects/official-wasm.ts Introduces iterateWithStatement generator to keep sqlite-wasm prepared statements alive until iteration completes, then finalizes them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@subframe7536 subframe7536 merged commit 976f2b8 into master Jul 3, 2026
1 check passed
@subframe7536 subframe7536 deleted the codex/review-packages-for branch July 3, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants